package com.sjzsqjy.asdtiang.util;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;

public class MyStrutsPrepareAndExecuteFilter extends
		StrutsPrepareAndExecuteFilter {
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		/**
		 * web.xml配置如下：
		 *  <servlet-mapping>
		 * <servlet-name>ConnectorServlet</servlet-name>
		 * <url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern>
		 * </servlet-mapping>
		 * 列出不被包含的目录用正则表达式，排除不被struts2拦截的目录
		 */
		String regex = "(/fckeditor+)"; 
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(request.getRequestURI());
		if (matcher.find()) {
			chain.doFilter(req, res);
		} else {
			super.doFilter(req, res, chain);
		}
	}
}